<template>
  <!-- 标签页 -->
  <div class="xtx-tab">
    <!-- 标签页-头部 -->
    <div class="xtx-tab-head">
      <a
        v-for="item in tabs"
        :key="item.title"
        @click="changeTab(item)"
        :class="{active:item.name===value}"
      >{{item.title}}</a>
    </div>
    <!-- 标签页-内容 -->
    <div class="xtx-tab-body">
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'xtx-tab',
  props: {
    // tab选项卡列表 [{title,name}]
    tabs: {
      required: true,
      type: Array
    },
    // 当前激活选修卡
    value: {
      required: true
    }
  },
  methods: {
    // 点击选项卡
    changeTab (item) {
      if (item.name === this.value) return
      this.$emit('input', item.name)
    }
  }
}
</script>

<style scoped lang='less'>
.xtx-tab {
  .xtx-tab-head {
    height: 60px;
    width: 100%;
    border-bottom: 1px solid #f5f5f5;
    > a {
      width: 107px;
      height: 100%;
      border-right: 1px solid #f5f5f5;
      float: left;
      line-height: 59px;
      text-align: center;
      font-size: 16px;
      border-top: 2px solid transparent;
      cursor: pointer;
      user-select: none;
      &.active {
        color: @xtxColor;
        border-top-color: @xtxColor;
        background: #ffffff;
        height: 60px;
      }
    }
  }
}
</style>
